import request from '@/utils/request'

/**
 * 添加收藏
 * @param {Number} activityId 活动ID
 * @returns {Promise}
 */
export function addCollection(activityId) {
  return request({
    url: '/api/activity/collect',
    method: 'post',
    params: { activityId, type: 1 }
  })
}

/**
 * 取消收藏
 * @param {Number} activityId 活动ID
 * @returns {Promise}
 */
export function cancelCollection(activityId) {
  return request({
    url: '/api/activity/collect',
    method: 'post',
    params: { activityId, type: 0 }
  })
}

/**
 * 检查用户是否已收藏活动
 * @param {Number} activityId 活动ID
 * @returns {Promise}
 */
export function checkUserCollected(activityId) {
  return request({
    url: `/api/activity/check/${activityId}`,
    method: 'get'
  })
}

/**
 * 获取用户的收藏列表
 * @param {Object} params 查询参数
 * @returns {Promise}
 */
export function getUserCollections(params) {
  return request({
    url: '/collection/user',
    method: 'get',
    params
  })
}

/**
 * 获取活动的收藏数量
 * @param {Number} activityId 活动ID
 * @returns {Promise}
 */
export function getActivityCollectionCount(activityId) {
  return request({
    url: `/activity/count/activity/${activityId}`,
    method: 'get'
  })
}

/**
 * 获取活动的收藏数量（别名方法，与getActivityCollectionCount功能相同）
 * @param {Number} activityId 活动ID
 * @returns {Promise}
 */
export function countActivityCollections(activityId) {
  return getActivityCollectionCount(activityId)
}
